package com.guigu.tms.result;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;

import java.io.Serializable;
import java.util.Objects;

/**
 * @ClassName:R
 * @Description://TODO
 * @Author:taoLong
 * @Date:2021/10/26:9:29 星期二
 * @email:2391611102@qq.com or 2391611102qq@gmail.com
 */
@ApiModel(value = "统一结果返回集", description = "本对象是私有构造,不能直接实例化对象")
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1162007547621477787L;
    @ApiModelProperty(name = "code", value = "状态码")
    private String code;
    @ApiModelProperty(name = "message", value = "返回消息")
    private String message;
    @ApiModelProperty(name = "flag", value = "状态")
    private Boolean flag;
    @ApiModelProperty(name = "data", value = "数据")
    private T data;

    public R(String code, String message, Boolean flag, T data) {
        this.code = code;
        this.message = message;
        this.flag = flag;
        this.data = data;
    }

    public R(String code, String message, Boolean flag) {
        this.code = code;
        this.message = message;
        this.flag = flag;
    }

    public R(String code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public R(String code, T data) {
        this.code = code;
        this.data = data;
    }

    public R() {
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Boolean getFlag() {
        return flag;
    }

    public void setFlag(Boolean flag) {
        this.flag = flag;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        R<?> r = (R<?>) o;
        return Objects.equals(code, r.code) && Objects.equals(message, r.message) && Objects.equals(flag, r.flag) && Objects.equals(data, r.data);
    }

    @Override
    public int hashCode() {
        return Objects.hash(code, message, flag, data);
    }

    @Override
    public String toString() {
        return "R{" +
                "code='" + code + '\'' +
                ", message='" + message + '\'' +
                ", flag=" + flag +
                ", data=" + data +
                '}';
    }
}
